$(function(){
    if($('.star')){
        $.each($('.star'), function(index, row){
            var starcount = $(row).find('b').text();
            selectstar($(row), starcount-1);
        })
    }
});

var msg = ['完全没效果','效果很差','效果一般','效果不错','效果非常好'];

$('.star li').click(function(){
    var star = $(this).parent().parent();
    var index = $(star).find('li').index($(this));
    selectstar(star, index);
});

function selectstar(star, index){
    $(star).find('li:lt(' + (index+1) + ')').attr('class','on');
    $(star).find('li:gt(' + index + ')').attr('class','');
    var sindex = $('.star').index($(star));
    $('.star').eq(sindex).find('span').text(msg[index]);
    $(star).find('b').text(index+1);
};

$('#submit').click(function(){
    var starlist = $('.star');
    var zdscore = 0;
    if(starlist){
        var hascontent = false;
        var scorelist = [];
        $.each(starlist, function(index, row){
            if(index == 0){
                zdscore = parseInt($(row).find('b').text());
            }
            else if(index > 0){
                var selectcount = parseInt($(row).find('b').text());
                var prodno = $(row).find('i').text();
                if(selectcount>0){
                    scorelist.push({prod_no:prodno, score:selectcount})
                    if(selectcount<3){
                        hascontent = true;
                    }
                }
            }
        });
        if(hascontent && !$('#evaluatecontent').val()){
            $.Dialog.fail("需要您的意见噢！");//成功调用 提示一秒后自动关闭
            return false;
        }
        else if(zdscore == 0){
            $.Dialog.fail("需要您对整单进行打分");//成功调用 提示一秒后自动关闭
            return false;
        }
        else{
            $.Dialog.loading();
            $.ajax({
                url:yxevaluate.yxpostEvaluate,
                type:"post",
                data:{listid: $('#listid').val(), mdcode:$('#mdcode').val(), dbid:$('#dbid').val(), content:$('#evaluatecontent').val(), symptom:$('#evaluatesymptom').val(), score:zdscore, scorelist:scorelist},
                dataType:"json",
                success:function(data){
                    switch (data.statu){
                        case 0:
                            $.Dialog.success(data.content);
                            setTimeout(function(){
                                location.href = yxevaluate.showcostRecord;
                            },2000);
                            break;
                        case 1:
                            $.Dialog.fail(data.content);
                            break;
                    }
                }
            });
        }
    }
});

$('#showypdetailbtn').click(function(){
    if($('#ypdetail').is(":hidden")){
        $('#ypdetail').show();
        $(this).text('隐藏消费明细')
    }
    else{
        $('#ypdetail').hide();
        $(this).text('显示消费明细')
    }
});
$('.seefullbtn').click(function(){
    var ctl_div = $(this).parent().parent().prev().find('.h72');
    var height = ctl_div[0].scrollHeight;
    console.log(height);
    if(height > 66){
        ctl_div.css("max-height","none");
    }
    $(this).hide();
});